<template>
  <h1>员工列表练习</h1>
  <input type="text" v-model="emp.name" placeholder="请输入员工姓名">
  <input type="text" v-model="emp.salary" placeholder="请输入员工工资">
  <input type="text" v-model="emp.job" placeholder="请输入员工岗位">
  <button @click="add">点我添加</button>
  <hr>
  <table border="1">
    <tr>
      <th>编号</th>
      <th>姓名</th>
      <th>工资</th>
      <th>岗位</th>
    </tr>
    <tr v-for="(item,index) in empArr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.job}}</td>
    </tr>
  </table>

</template>


<script setup>
  import { ref } from 'vue';
  const emp = ref({
    name: '',
    salary: '',
    job: ''
  });
  const empArr = ref([]);

  const add = () => {
    if(emp.value.name.trim() === '' || emp.value.salary.trim() === '' || emp.value.job.trim() === ''){
      alert('输入信息不能为空');
      return;
    }
    empArr.value.push(emp.value)
    emp.value = {};
    console.log(empArr);
  }
</script>



<style scoped>

</style>